<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               ref="crud"
               v-model="form"
               :defaults.sync="showColumn"
               :permission="permissionList"
               :page.sync="page"
               :before-open="beforeOpen"
               @sortable-change="sortableChange"
               @row-del="rowDel"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @refresh-change="refreshChange"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @filter="filterChange"
               @sort-change="sortChange"
               @row-dblclick="handleRowDBLClick"               
               @on-load="onLoad">
      <template slot-scope="scope" slot="menuForm">
        <div  style="text-align:right; float:right">
          <el-button type="text"  v-if="operateType == 'edit'"   icon="el-icon-time" style="font-weight:normal;" size="large" @click.stop="getHistoryRecord">修改历史</el-button>
        </div> 
      </template>
      <template slot-scope="scope" slot="menuLeft">
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="permission.sys_micro_service_config_batch_delete"
                   @click.stop="handleDelete">删 除
        </el-button>
      </template>
      <template slot="menuRight">
        <el-button v-if="permission.sys_micro_service_config_upload" type="default" @click.stop="openBatchAddDialog"  title="上传" icon="el-icon-upload" circle size="small"></el-button>
        <el-button v-if="permission.sys_micro_service_config_download" type="default" @click.stop="exportExcel"  title="下载" icon="el-icon-download" circle size="small"></el-button>
      </template>
      <!-- 组件管理 -->
      <template  slot="componentForm" slot-scope="scope">
        <div class="msgBody">

          <el-button  v-if="operateType == 'edit'"  type="primary"
                     size="small"
                     icon="el-icon-plus"
                     @click.stop="componentBatchAdd(scope.row)">添加组件
          </el-button>
           <el-button  v-if="operateType == 'edit'"  type="primary"
                     size="small"
                     icon="el-icon-plus"
                     @click.stop="processBatchAdd(scope.row)">添加流程
          </el-button>
          <el-button  v-if="operateType == 'add'" type="primary"
                     disabled
                     size="small"
                     icon="el-icon-plus">请保存后通过编辑增加
          </el-button>
          <avue-crud :option="componentOption" 
               :data="componentData"
               :table-loading="componentLoading" 
               ref="componentCrud"
               v-model="componentForm"
               :before-open="componentBeforeOpen"
               @sortable-change="componentSaveOrUpdate"
               @row-del="componentRowDel"
               @row-update="componentRowUpdate"
               @row-save="componentRowSave"
               @refresh-change="componentRefreshChange"
               @sort-change="sortChange"
               @row-dblclick="componentHandleRowDBLClick"               
               @on-load="componentOnLoad">
            <template slot-scope="scope" slot="menu">
              <el-button type="text"
                      size="small"
                      icon="el-icon-edit"
                      @click.stop="openMappingDialog(scope.row)">接口映射
              </el-button>
            </template>
          </avue-crud>
          
        </div>
      </template>
        <!-- 数据总线 -->
        <template slot="dataBusForm" slot-scope="scope">
          <div class="msgBody">
            <el-button type="primary"
                      size="small"
                      icon="el-icon-plus"
                      @click.stop="cloumnBatchAdd(scope.row, 'databus')">数据总线字段
            </el-button>
            <avue-crud  :option="databusOption" 
                          :data="databusData"
                          ref="databusCrud"
                          v-model="databusForm"
                          :page.sync="databusPage"
                          @row-del="databusRowDel"
                          @row-save="databusRowSave"
                          @row-update="databusRowSave"
                          @sort-change="sortChange"
                          @sortable-change="databusSortChange"
                          >
                  <template slot-scope="scope" slot="columnName">
                      <div v-if="scope.row.dataType == 'array'" style="color: #3c8dda" @click="databusBeforeOpen(scope.row)">
                        {{scope.row.columnName}}
                      </div>
                      <div  v-else >
                        {{scope.row.columnName}}
                      </div>
                  </template>
                  <template slot-scope="scope" slot="operatorForm">
                      <div>
                        <el-button type="primary"
                                  size="small"
                                  icon="el-icon-plus"
                                  @click.stop="cloumnBatchAdd(scope.row, 'array')">添加字段
                        </el-button>
                      </div>
                  </template>
            </avue-crud>
          </div>
        </template>
        <!-- 输入输出 -->
      	<template slot="serviceInputMsgBodyForm" slot-scope="scope">
          <div class="msgBody">
            <el-button type="primary"
                      size="small"
                      icon="el-icon-plus"
                      @click.stop="cloumnBatchAdd(scope.row, 'input')">输入接口字段
            </el-button>
            <avue-crud  :option="serviceInputOption" 
                          :data="serviceInputData"
                          ref="serviceInputCrud"
                          v-model="inputForm"
                          :page.sync="serviceInputPage"
                          @row-del="serviceInputRowDel"
                          @row-update="inputDataRowUpdate"
                          @sort-change="sortChange"
                          @sortable-change="serviceInputSortChange"
                          >
                  <template slot-scope="scope" slot="columnName">
                      <div v-if="scope.row.dataType == 'array'" style="color: #3c8dda" @click="inputDataBeforeOpen(scope.row)">
                        {{scope.row.columnName}}
                      </div>
                      <div  v-else >
                        {{scope.row.columnName}}
                      </div>
                  </template>
                   <template slot-scope="scope" slot="operatorForm">
                      <div>
                        <el-button type="primary"
                                  size="small"
                                  icon="el-icon-plus"
                                  @click.stop="cloumnBatchAdd(scope.row, 'array')">添加字段
                        </el-button>
                      </div>
                  </template>
            </avue-crud>
          </div>
        </template>
        <template  slot="serviceOutputMsgBodyForm" slot-scope="scope">
          <div class="msgBody">
            <el-button type="primary"
                      size="small"
                      icon="el-icon-plus"
                      @click.stop="cloumnBatchAdd(scope.row, 'output')">输出接口字段
            </el-button>
            <avue-crud  :option="serviceInputOption" 
                          :data="serviceOutputData"
                          ref="serviceOutputCrud"
                          v-model="serviceOutputForm"
                          :page.sync="serviceOutputPage"
                          @row-del="serviceOutputRowDel"
                          @row-update="outputDataRowUpdate"
                          @sort-change="sortChange"
                          @sortable-change="serviceOutputSortChange"
                          >
                  <template slot-scope="scope" slot="columnName">
                      <div v-if="scope.row.dataType == 'array'" style="color: #3c8dda" @click="outputDataBeforeOpen(scope.row)">
                        {{scope.row.columnName}}
                      </div>
                      <div  v-else >
                        {{scope.row.columnName}}
                      </div>
                  </template>
                   <template slot-scope="scope" slot="operatorForm">
                      <div>
                        <el-button type="primary"
                                  size="small"
                                  icon="el-icon-plus"
                                  @click.stop="cloumnBatchAdd(scope.row, 'array')">添加字段
                        </el-button>
                      </div>
                  </template>
            </avue-crud>
          </div>
        </template>
        <template  slot="msgBodyMappingForm" slot-scope="scope">
          <div class="msgBody">
            暂无映射
          </div>
        </template>
    </avue-crud>
    <!-- 
      批量添加字段对话框
     -->
    <el-dialog  title="批量添加接口字段" 
      width='70%' 
      top="6vh"
      :close-on-click-modal='false' 
      :visible.sync="batchAddColumnDialog"
      destroy-on-close='true'
      center
      >
      <el-row>
        <el-col :span="5">
          <el-input
            type="textarea"
            :autosize="{ minRows: 20, maxRows: 20}"
            placeholder="可直接从excel粘贴变量中文名"
            v-model="importDataArea"
            @change='handleImport'
            >
          </el-input>
        </el-col>
        <el-col :span="19">
          <el-table
            :data="allFieldData"
            height="430"
            border
            v-loading="tabLoading"
            :row-class-name="tableRowClassName"
            style="width: 100%"
            >
            <el-table-column
              prop="oldColumnComment"
              label="字段中文"
              width="150">
            </el-table-column>
            <el-table-column
              prop="columnName"
              label="字段名字"
              width="200">
            </el-table-column>
            <el-table-column
              prop="dataTypeFmt"
              label="数据类型"
              width="200">
            </el-table-column>
            <el-table-column
              prop="columnFullName"
              label="全名"
              width="120">
            </el-table-column>
            <el-table-column
              fixed="right"
              label="状态操作"
              width="150">
              <template slot-scope="scope">
                <el-tag  v-if="scope.row.foundFlag == 'root' || scope.row.foundFlag == 'find'"  size="small">需加变量库</el-tag>
                <el-tag  v-if="scope.row.foundFlag == 'field'"  >已在变量库</el-tag>
                <el-tag  v-if="scope.row.foundFlag == 'lostRoot'"  type="warning">缺失词根</el-tag>
                <el-tag  v-if="scope.row.foundFlag == 'lostAttrRoot'"  type="danger">缺失定语&词根</el-tag>
                <el-tag  v-if="scope.row.foundFlag == 'lostAttr'" type="success">缺失定语</el-tag>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
      
      <div slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" id="copyBtn" @click="handleBatchImport($event)" >批量添加字段</el-button>
        <el-button size="small" @click="batchAddColumnDialog = false">取 消</el-button>
      </div>
    </el-dialog>

     <!-- 
      批量添加组件对话框
     -->
    <el-dialog title="批量添加组件"  width="80%" top="5vh" :close-on-click-modal='false' :visible.sync="addComponentDialog">
      <sys-micro-component-dialog
        ref="componentDialog"
        @handleBatchAdd="handleBatchAdd">
      </sys-micro-component-dialog>
    </el-dialog>

    <!-- 
      批量添加流程
     -->
    <el-dialog title="批量添加流程"  width="80%" top="5vh" :close-on-click-modal='false' :visible.sync="addProcessDialog">
      <sys-micro-process-dialog
        ref="processDialog"
        @handleBatchAddProcess="handleBatchAddProcess">
      </sys-micro-process-dialog>
    </el-dialog>

    <!-- 
      总线映射对话框
     -->
    <el-dialog :title="'总线接口映射——'+componentForm.componentName"  :fullscreen='true' :close-on-click-modal='false' :visible.sync="msgBodyMappingDialog">
      <sys-micro-service-component-mapping
        ref="msgMappingDialog"
        :serviceBusData="databusData"
        :serviceComponentData="componentForm"
        @closeMappingDialog="closeMappingDialog"
        @saveMappingData="saveMappingData">
      </sys-micro-service-component-mapping>
    </el-dialog>


    <!-- 批量导入数据 -->
    <upload-excel ref="uploadExcel" :actionUrl='actionUrl' ></upload-excel>
    <!-- 历史记录 -->
    <update-history ref="historyRecord"></update-history>
  </basic-container>
</template>

<script>
import {exportSysMicroServiceComponentExcel,saveOrUpdateSysMicroServiceComponent,saveOrUpdateSysMicroServiceComponentList,saveSysMicroServiceComponent,saveSysMicroServiceComponentList,deleteSysMicroServiceComponent,querySysMicroServiceComponent,querySysMicroServiceComponentListPage,updateSysMicroServiceComponent,deleteSysMicroServiceComponentList} from '@/api/micro/sysMicroServiceComponentApi';

import {autoGetSysToolDictFieldList} from '@/api/tool/sysToolDictFieldApi';
import {exportSysMicroServiceConfigExcel,saveOrUpdateSysMicroServiceConfig,saveOrUpdateSysMicroServiceConfigList,saveSysMicroServiceConfig,saveSysMicroServiceConfigList,deleteSysMicroServiceConfig,querySysMicroServiceConfig,querySysMicroServiceConfigListPage,updateSysMicroServiceConfig,deleteSysMicroServiceConfigList} from '@/api/micro/sysMicroServiceConfigApi';
import {mapGetters} from 'vuex';
import { reqCommonMsg } from '@/util/reqCommonMsg';
import {filterFormat} from '@/util/util';
import SysMicroComponentDialog from '@/views/system/micro/sysMicroComponentDialog.vue'
import SysMicroProcessDialog from '@/views/system/micro/sysMicroProcessDialog.vue'
import SysMicroServiceComponentMapping from '@/views/system/micro/sysMicroServiceComponentMapping.vue'
export default {
  components: {
    SysMicroComponentDialog,
    SysMicroProcessDialog,
    SysMicroServiceComponentMapping
  },
  data() {
    return {
      //批量导入
      actionUrl: '/micro/sysMicroServiceConfig/uploadExcel',

      //文件选择器的打开方式 add新增、edit修改、view 查看
      openType: 'edit',
      // 当前打开form对话框操作类型 
      operateType: 'add',

      //添加组件对话框
      addComponentDialog: false,

      //添加流程对话框
      addProcessDialog: false,

      //报文映射
      msgBodyMappingDialog: false,

      // 表字段定义区
      columnSelectionList: [],
      allFieldData:[],
      tabLoading: false,
      importDataArea: 'ID\n租户ID',
      batchAddColumnDialog: false,
      currentFieldRow:{},
      columnForm: {},

      importDataArea: '',
      batchAddDialog: false,
      form: {},
      currentRow: {},
      selectionList: [],
      loading: true, 
      showColumn: [],
      option: {
        labelPosition: 'right',
        labelSuffix: '：',
        labelWidth: 125,
        dialogTop: '50',
        indexFixed:true, 
        stripe:true,
        calcHeight: 80,
        searchShow: true,
        searchMenuSpan: 6,
        tip: false,
        border: true,
        index: true,
        selection: true,
        addBtn: true,
        viewBtn: true,
        delBtn: true,
        cancelBtn: true,
        printBtn:false,
        saveBtn: true,
        editBtnText: '服务配置',
        filterBtn:true,          
        menuWidth: 220,
        dialogMenuPosition: 'center',
        dialogDirection:'rtl',
        dialogType:'dialog',
        dialogFullscreen:false,
        dialogClickModal:false,
        dialogWidth: '70%',
        highlightCurrentRow:  true,
        sortable: true,
        column: [
          {
            label: '所属应用名',
            prop: 'belongAppId', 
            type: 'select', 
            search: true,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            filterable: true,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 50,
            overHidden: true,
            rules: [{
              message: '请输入所属应用名',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '服务编码',
            prop: 'serviceCode', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            filterable: true,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 50,
            overHidden: true,
            rules: [{
              message: '请输入服务编码',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '服务类型',
            prop: 'serviceType', 
            type: 'select', 
            search: true,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            filterable: true,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 50,
            overHidden: true,
            value: 'S',
            rules: [{
              message: '请输入服务编码',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[{
              label: '服务',
              value: 'S'
            },
            {
              label: '流程',
              value: 'P'
            }],
          },
          {
            label: '服务名称',
            prop: 'serviceName', 
            type: 'input', 
            search: true,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            filterable: true,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 50,
            overHidden: true,
            rules: [{
              message: '请输入服务名称',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          
          {
            label: '服务描述',
            prop: 'serviceDesc', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            filterable: true,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 2000,
            overHidden: true,
            rules: [{
              message: '请输入服务描述',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 200,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '写日志标识',
            prop: 'writeLogFlag', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            filterable: true,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 1,
            overHidden: true,
            rules: [{
              message: '请输入写日志标识',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 1,
              message: '内容长度不能超过1字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '分录拆分方式',
            prop: 'entrySplitWay', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            filterable: true,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 30,
            overHidden: true,
            rules: [{
              message: '请输入分录拆分方式',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '入账方式',
            prop: 'postingWay', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            filterable: true,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 30,
            overHidden: true,
            rules: [{
              message: '请输入入账方式',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '转主机报文标识',
            prop: 'toMainframeMsgFlag', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            filterable: true,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 1,
            overHidden: true,
            rules: [{
              message: '请输入转主机报文标识',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 1,
              message: '内容长度不能超过1字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '交易类型',
            prop: 'transType', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            filterable: true,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 30,
            overHidden: true,
            rules: [{
              message: '请输入交易类型',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
        ],
        tabs: true,
        menuBtn: true,
        tabsActive: 1,
        group: [
          {
            label: '服务数据总线',
            prop: 'serviceDataBus',
            column: [
              {
                labelWidth:30,
                label: '',
                prop: 'dataBus',
                span: 24,
                hide:true,
                formslot:true,
              }
            ]
          },
          {
            label: '输入/输出接口',
            prop: 'basicInfo',
            column: [
              {
                labelWidth:30,
                label: '',
                prop: 'serviceInputMsgBody',
                span: 12,
                hide:true,
                formslot:true,
              },
              {
                labelWidth:30,
                label: '',
                prop: 'serviceOutputMsgBody',
                span: 12,
                hide:true,
                formslot:true,
              }
            ]
          },
          {
            label: '组件列表',
            prop: 'componentList',
            column: [
              {
                labelWidth:20,
                label: '',
                prop: 'component',
                span: 24,
                hide:true,
                formslot:true,
              }
            ]
          },
          {
            label: '报文转化映射',
            prop: 'msgBodyList',
            column: [
              {
                labelWidth:20,
                label: '',
                prop: 'msgBodyMapping',
                span: 24,
                hide:true,
                formslot:true,
              }
            ]
          }
        ]
      },
      data: [],

      // 组件区
      componentForm: {},
      componentCurrentRow: {},
      componentLoading: false, 
      componentOption: {
        columnBtn: false,
        refreshBtn: true,
        labelPosition: 'right',
        labelSuffix: '：',
        labelWidth: 125,
        dialogTop: '50',
        indexFixed:true, 
        stripe:true,
        calcHeight: 80,
        searchShow: true,
        searchMenuSpan: 6,
        tip: false,
        border: true,
        index: true,
        selection: false,
        addBtn: false,
        viewBtn: false,
        editBtn: true,
        delBtn: true,
        delBtnText: '移除',
        cancelBtn: true,
        cellBtn:true,
        printBtn:false,
        saveBtn: true,
        filterBtn:false,          
        menuWidth: 220,
        dialogMenuPosition: 'center',
        dialogDirection:'rtl',
        dialogType:'dialog',
        dialogFullscreen:false,
        dialogClickModal:false,
        dialogWidth: '80%',
        highlightCurrentRow:  true,
        searchShow:true,
        sortable:true,
        emptyText:'暂无组件',
        addBtnText:'新增组件',
        column: [
          {
            label: '所属应用',
            prop: 'belongAppId', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            filterable: true,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 50,
            overHidden: true,
            width: 100,
            rules: [{
              message: '请输入所属应用名',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '类型',
            prop: 'type', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            filterable: true,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 50,
            overHidden: true,
            width: 100,
            rules: [{
              message: '请输入所属应用名',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[
              {
                label: '组件',
                value: 'C'
              },
              {
                label: '流程',
                value: 'P'
              }
            ],
          },
          {
            label: '组件编码',
            prop: 'componentCode', 
            type: 'input', 
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            filterable: true,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 50,
            width:150,
            overHidden: true,
            rules: [{
              message: '请输入组件编码',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '组件名称',
            prop: 'componentName', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            filterable: true,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 50,
            width:200,
            overHidden: true,
            rules: [{
              message: '请输入组件名称',
              required:  true,
              trigger: 'blur'
            },
            
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          
          {
            label: '执行条件',
            prop: 'execCondition', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            filterable: true,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 500,
            overHidden: true,
            cell: true,
            rules: [{
              message: '请输入执行条件',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 500,
              message: '内容长度不能超过500字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '输入映射关系',
            prop: 'inputMappingRelation', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            filterable: true,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 5000,
            overHidden: true,
            rules: [{
              message: '请输入输入映射关系',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 5000,
              message: '内容长度不能超过5000字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '输出映射关系',
            prop: 'outputMappingRelation', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            filterable: true,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 5000,
            overHidden: true,
            rules: [{
              message: '请输入输出映射关系',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 5000,
              message: '内容长度不能超过5000字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
        ]
      },
      componentData: [],
      // 数据总线
      databusData: [],
      databusForm: {},
      databusCurrentRow: {},
      databusLoading: true, 
      databusOption: {
        columnBtn: false,
        refreshBtn: false,
        index: true,
        stripe:true,
        calcHeight: 80,
        searchShow: true,
        searchMenuSpan: 6,
        tip: false,
        border: true,
        selection: false,
        addBtn: false,
        viewBtn: false,
        delBtn: true,
        cancelBtn: true,
        printBtn:false,
        saveBtn: true,
        filterBtn: false,     
        editBtn: true,  
        cellBtn: true,     
        menuWidth: 150,
        delBtnText: '删除',
        updateBtnText: '保存',
        dialogMenuPosition: 'center',
        dialogDirection:'rtl',
        dialogType:'dialog',
        dialogFullscreen:false,
        dialogClickModal:false,
        dialogWidth: '70%',
        highlightCurrentRow:  true,
        searchShow:true,
        sortable:true,
        emptyText:'暂无字段',
        addBtnText:'新增接口字段',
        column: [
          {
            label: '接口字段',
            prop: 'columnName', 
            type: 'input',
            display: false,
          },
          {
            label: '字段类型',
            prop: 'dataType', 
            type: 'input',
            width: 150,
            display: false,
          },
          {
            label: '字段说明',
            prop: 'columnComment', 
            type: 'input',
            display: false,
          },
          {
            label: '默认值',
            prop: 'defaultValue', 
            type: 'input',
            display: false,
            cell: true
          },
          {
            labelWidth: 105,
            label: '',
            prop: 'operator', 
            type: 'input',
            hide: true,
            formslot: true
          },
          {
            label: '数组项',
            prop: 'arrayObject', 
            type: 'dynamic', 
            span:24,
            hide: true,
            children: {
              align: 'center',
              headerAlign: 'center', 
              readonly: true,
              column: [
                {
                  label: '接口字段',
                  prop: 'columnName', 
                  type: 'input',
                  display: false,
                  disabled: true
                },
                {
                  label: '字段类型',
                  prop: 'dataType', 
                  type: 'input',
                  width: 150,
                  display: false,
                  disabled: true
                },

                {
                  label: '字段说明',
                  prop: 'columnComment', 
                  type: 'input',
                  display: false,
                  disabled: true
                }
              ]
            }
          }
        ]
      },

      // 输出接口区
      interfaceMode: 'input',
      serviceOutputForm: {},
      outputCurrentRow: {},
      outputLoading: true, 
      serviceOutputData: [],

      // 输入接口区
      serviceInputData: [],
      inputForm: {},
      inputCurrentRow: {},
      inputLoading: true, 
      serviceInputOption: {
        columnBtn: false,
        refreshBtn: false,
        index: true,
        stripe:true,
        calcHeight: 80,
        searchShow: true,
        searchMenuSpan: 6,
        tip: false,
        border: true,
        selection: false,
        addBtn: false,
        viewBtn: false,
        delBtn: true,
        cancelBtn: true,
        cellBtn:false,
        printBtn:false,
        saveBtn: false,
        filterBtn:false,     
        editBtn:false,       
        menuWidth: 50,
        delBtnText: ' ',
        updateBtnText: '保存',
        dialogMenuPosition: 'center',
        dialogDirection:'rtl',
        dialogType:'dialog',
        dialogFullscreen:false,
        dialogClickModal:false,
        dialogWidth: '70%',
        highlightCurrentRow:  true,
        searchShow:true,
        sortable:true,
        emptyText:'暂无字段',
        addBtnText:'新增接口字段',
        column: [
          {
            label: '接口字段',
            prop: 'columnName', 
            type: 'input',
            display: false,
          },
          {
            label: '字段类型',
            prop: 'dataType', 
            type: 'input',
            width: 110,
            display: false,
          },
          
          {
            label: '字段说明',
            prop: 'columnComment', 
            type: 'input',
            width: 120,
            display: false,
          },
          {
            labelWidth: 105,
            label: '',
            prop: 'operator', 
            type: 'input',
            hide: true,
            formslot: true
          },
          {
            label: '数组项',
            prop: 'arrayObject', 
            type: 'dynamic', 
            span:24,
            hide: true,
            children: {
              align: 'center',
              headerAlign: 'center', 
              readonly: true,
              column: [
                {
                  label: '接口字段',
                  prop: 'columnName', 
                  type: 'input',
                  display: false,
                  disabled: true
                },
                {
                  label: '字段类型',
                  prop: 'dataType', 
                  type: 'input',
                  width: 150,
                  display: false,
                  disabled: true
                },

                {
                  label: '字段说明',
                  prop: 'columnComment', 
                  type: 'input',
                  display: false,
                  disabled: true
                }
              ]
            }
          }
        ]
      },
      // 请求参数区
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      reqParams: {
        singleBody: {},
        listBody: [{}],
        sqlCondition:[],
        orderRule: [],
        currentPage: 1,
        pageSize: 10
      },
      commonData: null,
      conditions: [],
      orderRules: [],
      singleBody: {}
    };
  },
  computed: {
    ...mapGetters(['website','orgTree','genOrgTree','userInfo','permission','projectInfo']),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.sys_micro_service_config_add, false),
        viewBtn: this.vaildData(this.permission.sys_micro_service_config_view, false),
        delBtn: this.vaildData(this.permission.sys_micro_service_config_delete, false),
        editBtn: this.vaildData(this.permission.sys_micro_service_config_edit, false),
        printBtn: this.vaildData(this.permission.sys_micro_service_config_print, false),
        searchBtn:this.vaildData(this.permission.sys_micro_service_config_search, false)
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push({id : ele.id});
      });
      return ids;
    } 
  },
  methods: {
    /**
     * 启动流程
     */
    startFlow(row){
      this.currentRow = row;
      //flowOptFlag 1-开始启动 2-处理流程
      this.flowArea.isFlow = this.isFlow;
      this.flowArea.flowOptFlag = '1';
      this.processFlow();
    },
    /**
     * 启动流程，执行流程方法
     */
    processFlow(){
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
      });
      this.reqParams.flowArea = this.flowArea
      this.reqParams.singleBody = this.currentRow;
      this.commonData = reqCommonMsg(this.reqParams)
      updateSysMicroServiceConfig(this.commonData).then(() => {
        this.$message({
          customClass:'zZindex',
          type: 'success',
          message: '操作成功!'
        });
        loading.close();
      }, error => {
        window.z(error); 
        loading.close();
      });
    },
    /**
     * 加载列表数据
     */
    onLoad(page) {
   	  //如果和项目相关，请打开项目ID作为查询条件
      //if(!this.$project.checkChooseProject()){
      //  return false;
      //}
      //this.singleBody.projectId = this.projectInfo.id;
      this.loading = true;
      this.reqParams =  {
        singleBody: this.singleBody,
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage: page.currentPage, 
        pageSize: page.pageSize
      }
      this.commonData = reqCommonMsg(this.reqParams)
      querySysMicroServiceConfigListPage(this.commonData).then(res => {
        const data = res.data.body;
        this.page.total = data.total;
        this.data = data.listBody;
        this.loading = false;
        this.selectionClear();
      }, error => {
        this.loading = false; 
      });
    },
    /**
     * 新增一条记录
     */
    rowSave(row, done, loading) {
      this.reqParams.singleBody = row;
      this.reqParams.singleBody.serviceBusData = this.databusData;
      this.reqParams.singleBody.inputMsgBody = this.serviceInputData;
      this.reqParams.singleBody.outputMsgBody = this.serviceOutputData;
      let formatUser = {};
      this.commonData = reqCommonMsg(this.reqParams)
      saveSysMicroServiceConfig(this.commonData).then(() => {
        done();
        this.singleBody={};
        this.onLoad(this.page);
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
      }, error => {
        this.$console.log(error);
        done();
      });         
      //this.$console.log("row = ",row ,loading)
    },
    /**
     * 修改一条记录
     */
    rowUpdate(row, index, done, loading) {
      this.reqParams.singleBody = row;
      this.reqParams.singleBody.serviceBusData = this.databusData;
      this.reqParams.singleBody.inputMsgBody = this.serviceInputData;
      this.reqParams.singleBody.outputMsgBody = this.serviceOutputData;
      let formatUser = {};
      this.commonData = reqCommonMsg(this.reqParams)
      updateSysMicroServiceConfig(this.commonData).then(() => {
        done();
        this.singleBody={}
        this.onLoad(this.page);
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
      }, error => {
        this.$console.log(error);
        done();
      });
    },
    /**
     * 删除一条记录
     */
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.reqParams.singleBody = row;
          this.commonData = reqCommonMsg(this.reqParams);
          return deleteSysMicroServiceConfig(this.commonData);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
        }).catch(() => {});
    },
    /**
     * 双击打开详细窗口
     */
    handleRowDBLClick (row, event) {
      if(this.permission.sys_micro_service_config_dbclick){
        this.$refs.crud.rowView(row,row.$index);
      }
    },
    /**
     * 批量新增记录
     */
    openBatchAddDialog(){
      this.$refs.uploadExcel.openUploadDialog();
    },
    /**
     * 批量导入
     */
    handleImport() {
      const loading = this.$loading({
        lock: true,
        text: '处理中...',
        spinner: 'el-icon-loading',
      });
      var dataList = new Array();
      if(this.importDataArea){
        var lineList = this.importDataArea.split('\n')
        lineList.forEach((element,index) => {
          if(element.trim() != ''){
            var field = element.split('\t')
            var fieldList = {
              serviceCode:field[0].trim(),
              belongAppName:field[1].trim(),
              serviceName:field[2].trim(),
              serviceBusData:field[3].trim(),
              writeLogFlag:field[4].trim(),
              entrySplitWay:field[5].trim(),
              postingWay:field[6].trim(),
              toMainframeMsgFlag:field[7].trim(),
              transType:field[8].trim(),
              serviceInputMsgBody:field[9].trim(),
              serviceOutputMsgBody:field[10].trim(),
            }
            dataList[index] = fieldList
            //this.$console.log('fieldList = ',fieldList)
          }
        });
        //批量写入记录
        this.reqParams.listBody = dataList;
        this.commonData = reqCommonMsg(this.reqParams)
        saveSysMicroServiceConfigList(this.commonData).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          loading.close();
        }, error => {
          this.$console.log(error);
          loading.close();
        });      
      }
      else{
        this.loading=false;
        this.$message({
          type: 'warning',
          message: '数据格式不正确!'
        });
      }
    },
    /**
     * 搜索重置
     */
    searchReset() {
      this.conditions =[];
      this.singleBody = {};
      this.onLoad(this.page);
    },
    /**
     * 搜索
     */
    searchChange(params, done) {
      this.singleBody = params
      this.page.currentPage = 1;
      this.onLoad(this.page);
      done();
    },
    refreshChange(){
      this.onLoad(this.page);
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    /**
     * 处理批量删除
     */
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.reqParams.listBody = this.ids;
          this.commonData = reqCommonMsg(this.reqParams);
          return deleteSysMicroServiceConfigList(this.commonData);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.$refs.crud.toggleSelection();
        }).catch(() => {});
    },
    /**
     * 拷贝记录
     */
    handleCopy(row){
      this.$confirm('确定复制数据?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading=true;
        let copyValue=row;
        copyValue.id='0';
        copyValue.dataSign='0'
        copyValue.tableName='拷贝 '+ copyValue.tableName; 
        this.reqParams.singleBody = copyValue;
        this.commonData = reqCommonMsg(this.reqParams)
        saveSysToolTables(this.commonData).then(() => {
          this.singleBody={};
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.loading=false;
        }, error => {
          this.$console.log(error);
          this.loading=false;
        });
      }).catch(() => {});       
    },
    /**
     * 打开编辑、查询弹窗前查询记录
     */  
    beforeOpen(done, type) {
      if (['edit', 'view'].includes(type)) {
        this.operateType = 'edit';
        this.reqParams =  {
          singleBody: {
            id:this.form.id
          }
        }
        let commonData = reqCommonMsg(this.reqParams)
        const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading'
        });
        querySysMicroServiceConfig(commonData).then(res => {
          this.form = res.data.body.singleBody;
          this.form.inputMsgBody  = JSON.parse(this.form.inputMsgBody);
          this.form.outputMsgBody = JSON.parse(this.form.outputMsgBody);
          this.form.serviceBusData = JSON.parse(this.form.serviceBusData);
          this.serviceInputData = this.form.inputMsgBody;
          this.serviceOutputData = this.form.outputMsgBody;
          this.databusData = this.form.serviceBusData;
          this.componentData = [];
          this.componentLoad();
          loading.close();
          console.log('this.option.column.tabsActive==',this.option.column.tabsActive);
          this.option.tabsActive=3;
          done();
        }, error => {
          this.$console.log(error);
          loading.close();
          done();
        });
      }
      if (['add'].includes(type)) {
        this.option.tabsActive=1;
        this.operateType = 'add';
        this.serviceInputData = [];
        this.serviceOutputData = [];
        this.databusData = [];
        this.componentData = [];
        done();
      }
    },
    /**
     * 翻页查询
     */
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    /**
     * 更改每页条数
     */
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    /**
     * 自定义查询条件
     */
    filterChange(result) {
      this.page.currentPage = 1;
      this.conditions = filterFormat(result)
      this.onLoad(this.page);
    },
    /**
     * 列表排序
     */
    sortChange(val){
      this.orderRules=val
      this.onLoad(this.page);
    },
  
    /******组件处理开始 */
    /**
     * 加载组件列表数据
     */
    componentLoad() {
      this.singleBody.serviceCode = this.form.serviceCode;
      this.componentLoading = true;
      this.reqParams =  {
        singleBody: this.singleBody,
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule:{
          prop: 'showSeq',
          order: 'ascending' 
        },
        currentPage: 1, 
        pageSize: 9999
      }
      this.commonData = reqCommonMsg(this.reqParams)
      querySysMicroServiceComponentListPage(this.commonData).then(res => {
        const data = res.data.body;
        this.componentData = data.listBody;
        this.componentData.forEach(element => {
          element.inputMappingRelation  = JSON.parse(element.inputMappingRelation);
          element.outputMappingRelation = JSON.parse(element.outputMappingRelation);
        });
        this.componentLoading = false;
        this.singleBody = {};
      }, error => {
        this.componentLoading = false; 
      });
    },
    /**
     * 批量添加组件
     */
    componentBatchAdd(){
      this.addComponentDialog = true;
      setTimeout(() => {
        this.$refs.componentDialog.selectionClear(); 
      }, 500);
    },

    /**
     * 批量添加流程
     */
    processBatchAdd(){
      this.addProcessDialog = true;
      setTimeout(() => {
        this.$refs.processDialog.selectionClear(); 
      }, 500);
    },

    /**
     * 删除一条记录
     */
    componentRowDel(row) {
      this.$confirm('确定移除组件?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.reqParams.singleBody = row;
          this.commonData = reqCommonMsg(this.reqParams);
          return deleteSysMicroServiceComponent(this.commonData);
        })
        .then(() => {
          this.componentLoad();
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
        }).catch(() => {});
    },
    /**
     * 修改组件
     */
    componentRowUpdate(row, index, done, loading) {
      this.reqParams.singleBody = row;
      this.commonData = reqCommonMsg(this.reqParams)
      updateSysMicroServiceComponent(this.commonData).then(() => {
        done();
        this.singleBody={}
        this.componentLoad();
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
      }, error => {
        this.$console.log(error);
        done();
      });
    },
    /**
     * 打开编辑、查询弹窗前查询记录
     */  
    componentBeforeOpen(done, type) {
      if (['edit', 'view'].includes(type)) {
        this.operateType = 'edit';
        this.reqParams =  {
          singleBody: {
            id:this.form.id
          }
        }
        let commonData = reqCommonMsg(this.reqParams)
        const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading'
        });
        querySysMicroServiceComponent(commonData).then(res => {
          this.componentForm = res.data.body.singleBody;
          this.componentForm.inputMappingRelation  = JSON.parse(this.componentForm.inputMappingRelation);
          this.componentForm.outputMappingRelation = JSON.parse(this.componentForm.outputMappingRelation);
          // this.inputData = this.componentForm.inputMappingRelation;
          // this.outputData = this.componentForm.outputMappingRelation;
          loading.close();
          done();
        }, error => {
          this.$console.log(error);
          loading.close();
          done();
        });
      }
    },
    /**
     * 添加组件列表
     */
    handleBatchAdd(componentListValue){
      this.addComponentDialog = false;
      let newComponentList = [];
      // 判断是否有新增数据
      let dataLenght = this.componentData.length;
      componentListValue.forEach(element => {
        let foundFlag = false;
        this.componentData.forEach(celement => {
          if(element.componentCode == celement.componentCode){
            foundFlag = true;
          }
        });
        if(!foundFlag){
          dataLenght++;
          newComponentList.push({
            belongAppId: element.belongAppId,
            serviceCode: this.form.serviceCode,
            componentCode:  element.componentCode,
            componentName:  element.componentName,
            accessPath:  element.accessPath,
            accessMethodName:  element.accessMethodName,
            interfacePackageName:  element.interfacePackageName,
            type: 'C',
            execCondition: '',
            inputMappingRelation: [],
            outputMappingRelation: [],
            showSeq: dataLenght
          });
        }
      });
      if(newComponentList.length > 0){
        this.reqParams =  {
          transCode: '0001',
          listBody: newComponentList
        }
        this.commonData = reqCommonMsg(this.reqParams)
        saveOrUpdateSysMicroServiceComponentList(this.commonData).then(() => {
          this.$message({
            customClass:'zZindex',
            type: 'success',
            message: '添加成功!'
          });
          this.componentLoad();
        }, error => {
          //this.$console.log(error);
        });
      }

    },


    /**
     * 添加组件列表
     */
    handleBatchAddProcess(componentListValue){
      this.addProcessDialog = false;
      let newComponentList = [];
      // 判断是否有新增数据
      let dataLenght = this.componentData.length;
      componentListValue.forEach(element => {
        let foundFlag = false;
        this.componentData.forEach(celement => {
          if(element.componentCode == celement.componentCode || element.serviceCode == celement.componentCode){
            foundFlag = true;
          }
        });
        if(!foundFlag){
          dataLenght++;
          newComponentList.push({
            belongAppId: element.belongAppId,
            serviceCode: this.form.serviceCode,
            componentCode:  element.serviceCode,
            componentName:  element.serviceName,
            type: 'P',
            execCondition: '',
            inputMappingRelation: [],
            outputMappingRelation: [],
            showSeq: dataLenght
          });
        }
      });
      if(newComponentList.length > 0){
        this.reqParams =  {
          transCode: '0001',
          listBody: newComponentList
        }
        this.commonData = reqCommonMsg(this.reqParams)
        saveOrUpdateSysMicroServiceComponentList(this.commonData).then(() => {
          this.$message({
            customClass:'zZindex',
            type: 'success',
            message: '添加成功!'
          });
          this.componentLoad();
        }, error => {
          //this.$console.log(error);
        });
      }

    },
    /**
     * 排序
     */
    componentSaveOrUpdate(){
      // 整理顺序
      this.componentData.forEach((item, index) => {
        this.componentData[index].showSeq = index+1;
      }); 
      this.reqParams.listBody = this.componentData;
      this.commonData = reqCommonMsg(this.reqParams)
      saveOrUpdateSysMicroServiceComponentList(this.commonData).then(() => {
        this.componentLoad();
        this.$message({
          customClass:'zZindex',
          type: 'success',
          message: '保存成功!'
        });
      }, error => {
        //this.$console.log(error);
      });
    },

    /**
     * 组件报文和数据总线映射
     */
    openMappingDialog(row){
      this.msgBodyMappingDialog = true;
      this.componentForm =  row;
    },
    /**
     * 关闭映射对话框
     */
    closeMappingDialog(){
      this.msgBodyMappingDialog = false;
    },

    /**
     * 保存映射数据
     */
    saveMappingData(inputMappingData,outputMappingData){
      let isChange = false;
      if(JSON.stringify(this.componentForm.inputMappingRelation) != JSON.stringify(inputMappingData)){
        this.componentForm.inputMappingRelation = inputMappingData;
        isChange = true;
      }
      if(JSON.stringify(this.componentForm.outputMappingRelation) != JSON.stringify(outputMappingData)){
        this.componentForm.outputMappingRelation = outputMappingData;
        isChange = true;
      }
      //如果没有变化直接返回
      if(!isChange){
        this.$message({
          type: 'warning',
          message: '配置没有变化,无需保存!'
        });
        return false;
      }
      this.reqParams.singleBody = this.componentForm;
      this.commonData = reqCommonMsg(this.reqParams)
      updateSysMicroServiceComponent(this.commonData).then(() => {
        this.singleBody={}
        this.componentLoad();
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
        this.msgBodyMappingDialog = false;
      }, error => {
        this.$console.log(error);
        done();
      });
    },
    /******组件处理结束 */

   
    /**
     * 批量添加变量
     */
    cloumnBatchAdd(row,mode){
      this.batchAddColumnDialog = true;
      this.currentRow = row;
      this.interfaceMode = mode;
    },
    /**
     * 标准化数据
     */
    handleImport() {
      this.tabLoading=true;
      var dataList = new Array();
      if(this.importDataArea){
        var lineList = this.importDataArea.split('\n')
        var indx = 0;
        lineList.forEach((element,index) => {
          if(element != null && element.trim() != ''){
            var fieldList = {
              comment:element,
            }
            dataList[indx] = fieldList
            indx++;
            //console1.log('fieldList = ',fieldList)
          }
        });
        //批量写入记录
        this.reqParams.listBody = dataList;
        this.commonData = reqCommonMsg(this.reqParams)
        autoGetSysToolDictFieldList(this.commonData).then(res => {
          this.tabLoading=false;
          this.allFieldData = res.data.body.listBody;
        }, error => {
          //console1.log(error);
          this.tabLoading=false;
        });      
        //console1.log('lineList=',dataList)
      }
      else{
        this.tabLoading=false;
        this.$message({
          customClass:'zZindex',
          type: 'warning',
          message: '数据为空或不正确!'
        });
      }
    },
    /**
     * 批量添加字段到字段列表
     */
    handleBatchImport() {
      if(this.allFieldData.length <=0){
        this.$message({
          customClass:'zZindex',
          type: 'warning',
          message: '字段列表为空!'
        }); 
        return false;
      }
      this.$confirm('确定要导入字段数据到字段列表?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.batchAddColumnDialog = false;
          this.allFieldData.forEach((element,index) => {
            element.columnName = this.$toolUtil.toHump(element.columnName)
            this.cloumnAddRow(element);
          });
        })
        .then(() => { 
          this.$message({
            customClass:'zZindex',
            type: 'success',
            message: '操作成功!'
          }); 
        }).catch(() => {});
    },
    /**
     * 添加一个字段
     */
    cloumnAddRow(row) {
      let addElement = {
        columnName: row.columnName,
        dataType: row.dataTypeFmt,
        columnComment: row.columnComment,
        arrayObject: [],
        operator: ''
      }
      if(this.interfaceMode == 'input'){
        if(JSON.stringify(this.serviceInputData).indexOf('"'+row.columnName+'"') < 0){
          this.serviceInputData.push(addElement);
        }
      }
      else if(this.interfaceMode == 'output'){
        if(JSON.stringify(this.serviceOutputData).indexOf('"'+row.columnName+'"') < 0){
          this.serviceOutputData.push(addElement);
        }
      }
      else if(this.interfaceMode == 'databus'){
        if(JSON.stringify(this.databusData).indexOf('"'+row.columnName+'"') < 0){
          this.databusData.push(addElement);
        }
      }
      else if(this.interfaceMode == 'array'){
        if(JSON.stringify(this.currentRow.arrayObject).indexOf('"'+row.columnName+'"') < 0){
          this.currentRow.arrayObject.push(addElement);
        }
      }
    },
    /**
     * 删除数据总线字段
     */
    databusRowDel(row) {
      this.$confirm('确定删除数据总线字段?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.databusData.forEach((element,index) => {
            if(element.columnName == row.columnName){
              this.databusData.splice(index,1);
            }
          });
        })
        .then(() => {
        }).catch(() => {});
    },
    /**
     * 删除输入接口字段
     */
    serviceInputRowDel(row) {
      this.$confirm('确定删除接口字段?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.serviceInputData.forEach((element,index) => {
            if(element.columnName == row.columnName){
              this.serviceInputData.splice(index,1);
            }
          });
        })
        .then(() => {
        }).catch(() => {});
    },
    /**
     * 删除输出接口字段
     */
    serviceOutputRowDel(row) {
      this.$confirm('确定删除接口字段?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.serviceOutputData.forEach((element,index) => {
            if(element.columnName == row.columnName){
              this.serviceOutputData.splice(index,1);
            }
          });
        })
        .then(() => {
        }).catch(() => {});
    },
    /**
     * 总线字段排序
     */
    databusSortChange(oldindex, newindex, row, list) {
      this.databusData=[]
      this.$nextTick(()=>{
        this.databusData=list;
      })
    },

    /**
     * input接口排序
     */
    serviceInputSortChange(oldindex, newindex, row, list) {
      this.serviceInputData=[]
      this.$nextTick(()=>{
        this.serviceInputData=list;
      })
    },

    /**
     * output接口排序
     */
    serviceOutputSortChange(oldindex, newindex, row, list) {
      this.serviceOutputData=[]
      this.$nextTick(()=>{
        this.serviceOutputData=list;
      })
    },

    /**
     * 保存输入数组
     */
    inputDataRowUpdate(row, index, done, loading) {
      this.serviceInputData.forEach(element => {
        if(element.columnName == row.columnName){
          element.arrayObject = this.deepClone(row.arrayObject);
        }
      });
      console.log('====this.serviceInputData===',this.serviceInputData);
      done();
    },

    /**
     * 保存输出数组
     */
    outputDataRowUpdate(row, index, done, loading) {
      this.serviceOutputData.forEach(element => {
        if(element.columnName == row.columnName){
          element.arrayObject = this.deepClone(row.arrayObject);
        }
      });
      console.log('====this.serviceOutputData===',this.serviceOutputData);
      done();
    },

    /**
     * 保存总线数据
     */
    databusRowSave(row, index, done, loading) {
      this.databusData.forEach(element => {
        if(element.columnName == row.columnName){
          element.arrayObject = this.deepClone(row.arrayObject);
        }
      });
      // console.log('====this.databusData===',this.databusData);
      done();
    },
    /**
     * 输入对象字段打开前
     */
    inputDataBeforeOpen(row, event){
      this.$refs.serviceInputCrud.rowEdit(row,row.$index);
    },
    /**
     * 输入对象字段打开前
     */
    outputDataBeforeOpen(row,event){
      this.$refs.serviceOutputCrud.rowEdit(row,row.$index);
    },

    /**
     * 数据总线对象字段打开前
     */
    databusBeforeOpen(row,event){
      this.$refs.databusCrud.rowEdit(row,row.$index);
    },
    /**
     * 导出Excel
     */
    exportExcel() {
      this.reqParams =  {
        singleBody: this.singleBody,
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage:1, 
        pageSize: 100
      }
      // this.$console.log('reqParams = ',this.reqParams)
      this.commonData = reqCommonMsg(this.reqParams)
      exportSysMicroServiceConfigExcel(this.commonData);
    },
    /**
     * 获取业务字典参数
     */
    async getSysDict() {
      let dicData = await this.$params.getSysDict('["belongAppId"]');
      this.findObject(this.option.column, 'belongAppId').dicData = dicData.belongAppId;
      this.findObject(this.componentOption.column, 'belongAppId').dicData = dicData.belongAppId;
    },
    
    /**
     * 调用子组件方法查询历史
     */
    getHistoryRecord () {
      setTimeout(() => {
        this.$refs.historyRecord.getUpdateHistoryRecord(this.form.id);
      })
    },
  },
  created() {
    
    this.showColumn = this.$getStore({name: this.userInfo.userId+'sysMicroServiceConfigColumn'});
    //获取业务字典
    setTimeout(() => {
      this.getSysDict();
    }, 100);
    
    //加载机构
    let getOrgTreeTimer = setInterval(() => {
      if(this.genOrgTree){
        let orgTree = [];
        this.genOrgTree.forEach(element => {
          if(element.orgType == '1'){
            orgTree.push(element);
          }
        });
        clearInterval(getOrgTreeTimer);
      }
    }, 100);
  },
  watch: {
    showColumn: {
      handler(newValue, oldValue) {
        this.$setStore({name: this.userInfo.userId+'sysMicroServiceConfigColumn', content: this.showColumn});
      },
      deep: true
    }
  }
};
</script>
<style>
  .msgBody .el-table__header tr, .msgBody .el-table__header th , .msgBody .el-table__header td {
        padding: 0 !important;
        height: 40px !important;
  }

/* .msgBody .el-table__header{
   display: none !important;
 } */
 .msgBody .avue-crud__menu{
   display: none !important;
 }
 .msgBody .avue-crud__pagination{
   padding:5px !important;
   margin: 0px !important;
 }
 .msgBody .el-card__body{
   padding: 2px!important;
 }
</style>